const crypto = require('crypto');
import OpenAI from "openai";

export const hashTimestamp = (timestamp: string | number):string => {
  // 使用SHA-256进行哈希处理
  const hashedTimestamp = crypto.createHash('sha256').update(timestamp.toString()).digest('hex');
  return hashedTimestamp;
}

export const generateAiMessage = async (message: string) => {
  const openai = new OpenAI({
    baseURL: 'https://api.deepseek.com',
    apiKey: 'sk-07f8c56c196e4776be3afa097ac3ae71'
  });

  const completion = await openai.chat.completions.create({
    messages: [
      {
        role: "system",
        content: "你是一个优秀的博客总结助手，知识涵盖计算机编程和心理学。请遵守：\n" +
          "1. 绝对不使用任何Markdown符号（**、#、```等）\n" +
          "2. 用纯文本表达所有内容\n" +
          "3. 段落间用两个换行符分隔\n" +
          "4. 需要强调时用【】标注\n" +
          "5. 代码示例用「」包裹"
      },
      {
        role: "user",
        content: `请用纯文本总结以下文章（禁用Markdown）：\n${message}`
      }
    ],
    model: "deepseek-reasoner",
  });
  return completion.choices[0].message.content;
}